﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using TWPure.Token;
using TWPure.Token.Model;

namespace TWPure.TokenAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TokenController : ControllerBase
    {
        [HttpPost, Route("GetToken")]
        public string GetToken()
        {
            var tokenModel = HttpContext.Request.Form["tokenModel"];
            var encodedJwt = RayPIToken.IssueJWT(JsonConvert.DeserializeObject<TokenModel>(tokenModel), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
            return $"{encodedJwt}";
        }
    }
}